<?php

class Quad_Form_Element_RadioCollection extends Quad_Form_Element_OptionsCollection {
	
	protected $_memberClass = "Quad_Form_Element_Radio";
	
	public function __set($p,$v) {
		if ($p == 'selectedIndex') {
			return;
		}
		parent::__set($p,$v);
	}
	
	public function __get($p) {
		if ($p == 'selectedIndex') {
			return null;
		}
		parent::__get($p);
	}
	
	public function __toString() {
		$html = '';
		foreach ($this as $i => $radio) {
			$html .= (string) $radio . '<br />';
		}
		return $html;
	}
	
	public function getValue() {
		foreach ($this as $radio) {
			if ($radio->checked) {
				return $radio->checked;
			}
		}
		return null;
	}
	
	public function setValue($v) {
		$setAlready = false;
		foreach ($this as $radio) {
			if ($setAlready == false && $radio->value == $v) {
				$radio->checked = true;
				$setAlready = true;
			}
			else {
				$radio->checked = false;
			}
		}
		return $this;
	}	
	
}

